class Comment {
  final int id;
  final String content;
  final String time;
  final int userId;
  final int shareId;
  final int? topicId;

  Comment({
    required this.id,
    required this.content,
    required this.time,
    required this.userId,
    this.shareId = 0,
    this.topicId,
  });

  // 从JSON转换为Comment对象
  factory Comment.fromJson(Map<String, dynamic> json) {
    return Comment(
      id: json['id'],
      content: json['content'],
      time: json['time'],
      userId: json['userId'],
      shareId: json['shareId'] ?? 0,
      topicId: json['topicId'],
    );
  }

  // 将Comment对象转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'content': content,
      'time': time,
      'userId': userId,
      'shareId': shareId,
      if (topicId != null) 'topicId': topicId,
    };
  }
} 